
//websocket连接
let webSocket = null;
let wsUri = "ws://localhost:51578/";
window.onload = function () {
    console.log("window onload");
    try {
        webSocket = new WebSocket(wsUri);
    }catch (e) {
        console.log(e);
        return
    }
    webSocket.onopen = function () {
        console.log("websocket连接已建立，连接到：" + wsUri);
    };
    webSocket.onclose = function () {
        console.log("websocket连接已关闭");
    };
    webSocket.onmessage = function (e) {
        let l = e.data.split(" ");
	console.log(l);
	let pos4 = new AMap.LngLat(parseFloat(l[0]), parseFloat(l[1]));
         let pos3 = new AMap.LngLat(parseFloat(l[2]), parseFloat(l[3]));
                markerYellow.setPosition(pos4);
                markerRed.setPosition(pos3);
        // let location = JSON.parse(e.data);
        // console.log("[来自服务器]:");
        // console.log("latitude=", location.latitude);
        // console.log("longitude=", location.longitude);
       /* console.log(location);
        switch (location.deviceName) {
            case 'LC79D':
                let pos0 = new AMap.LngLat(location.longitude, location.latitude);
                markerRed.setPosition(pos0);
                break;
            case 'Qsens-V203':
                let pos1 = new AMap.LngLat(location.longitude, location.latitude);
                markerBlue.setPosition(pos1);
                break;
            case 'RAC-C1':
                let pos2 = new AMap.LngLat(location.longitude, location.latitude);
                markerGreen.setPosition(pos2);
                break;
            // case 'B96-F9K':
            //     let pos3 = new AMap.LngLat(location.longitude, location.latitude);
            //     markerRed.setPosition(pos3);
            //     break;
            // case 'ZED-F9P':
            //     let pos4 = new AMap.LngLat(location.longitude, location.latitude);
            //     markerYellow.setPosition(pos4);
            //     break;
            case 'error':
                let error = location.longitude;
                updateErrorCurve(error);
                break;
            default:
                
                break
        }*/
    };
    webSocket.onerror = function (e) {
        console.log("websocket连接遇到错误：" + e);
    };
};

function send(msg) {
    webSocket.send(JSON.stringify(msg));
}

let finishButton = document.getElementById("finishButton");
let startButton = document.getElementById("startButton");
let finishMessage = {
    finish : true,
    start : false
};
let startMessage = {
    finish : false,
    start : true
};
finishButton.onclick = function () {
    send(finishMessage);
};
startButton.onclick = function () {
    send(startMessage);
};

